package api

import (
	"blogdemo/gin/errmsg"
	"blogdemo/gin/model"
	"fmt"
	"github.com/gin-gonic/gin"
	"net/http"
)

func FindArticle(c *gin.Context) {
	username := c.Param("keyword")
	var article []model.Article
	var flag bool
	article, flag = model.SearchArticle(username)
	if !flag {
		c.JSON(http.StatusBadRequest, gin.H{
			"status": errmsg.ARTICLE_NOSER,
			"data":   article,
			"msg":    errmsg.GetErrMsg(errmsg.ARTICLE_NOSER),
		})
		fmt.Println("该关键词下没有文章记录")
		c.Abort()
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"status": errmsg.SUCCESS,
		"data":   article,
		"msg":    errmsg.GetErrMsg(errmsg.SUCCESS),
	})
	fmt.Println("成功获取该关键词下文章")
}
